package
        com.zzc.sale.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hos.entity.stock.Purchase;
import com.hos.entity.stock.PurchaseItem;
import com.hos.vo.Result;
import com.zzc.sale.service.PurchaseItemService;
import com.zzc.sale.service.PurchaseService;
import com.zzc.sale.vo.NewPurchaseVo;
import com.zzc.sale.vo.PurchaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.print.DocFlavor;
import java.util.List;
import java.util.Map;


/**
 * @author：xIAO_ZHOU_TX
 * @date：Created in 2023/12/18 16:18
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/sale/api/erp/purchase")
@Api(value = "采购入库相关接口",tags = "采购入库相关接口")
public class APIPurchaseController {
    @Resource
    private PurchaseService purchaseService;
    @Resource
    private PurchaseItemService purchaseItemService;
    @PostMapping("/listPurchaseForPage")
    @ApiOperation("分页查询所有的采购单数据【主页面】")
    public Result<Page<Purchase>> listPurchaseForPage(@RequestBody PurchaseVo purchaseVo){
        return new Result<>(200,"查询成功",purchaseService.listPurchaseForPage(purchaseVo));
    }
    @PostMapping("/doAudit/{purchaseId}")
    @ApiOperation("提交审核【主页面】")
    public Result doAudit(@PathVariable String purchaseId){
        return new Result<>(200,"提交成功", purchaseService.doAudit(purchaseId));
    }
    @PostMapping("/doInvalid/{purchaseId}")
    @ApiOperation("根据id修改状态改==>作废 【主页面】")
    public Result doInvalid(@PathVariable String purchaseId){
        return new Result<>(200,"提交成功", purchaseService.doInvalid(purchaseId));
    }
    @PostMapping("/doInventory/{purchaseId}")
    @ApiOperation("入库操作  【主页面】")
    public Result doInventory(@PathVariable String purchaseId){
        return new Result<>(200,"入库成功",purchaseService.doInventory(purchaseId));
    }
    @GetMapping("/generatePurchaseId")
    @ApiOperation("生成单据号【新增采购页面】")
    public Result generatePurchaseId(){
        return new Result<>(200,"生成成功",purchaseService.generatePurchaseId()) ;
    }
    @PostMapping("/addPurchase")
    @ApiOperation("添加采购单和详情【新增采购页面】")
    public Result<Integer> addPurchase(@RequestBody NewPurchaseVo newPurchaseVo){
        return new Result<>(200,"添加成功", purchaseItemService.addPurchase(newPurchaseVo));
    }

    @PostMapping("/erpAddPurchase")
    @ApiOperation("暂存【订单id页面】")
    public Result<Integer> erpAddPurchase(@RequestBody NewPurchaseVo newPurchaseVo){
        return new Result<>(200,"添加成功", purchaseItemService.erpAddPurchase(newPurchaseVo));
    }


    @PostMapping("/addPurchaseToAudit")
    @ApiOperation("添加采购单和详情并提交审核=>查看详情【新增采购页面】")
    public Result<Integer> addPurchaseToAudit(@RequestBody NewPurchaseVo newPurchaseVo){
        return new Result<>(200,"添加成功", purchaseItemService.addPurchaseToAudit(newPurchaseVo));
    }
    @PostMapping("/erpAddPurchaseToAudit")
    @ApiOperation("添加采购单和详情并提交审核=>查看详情【新增采购页面】")
    public Result<Integer> erpAddPurchaseToAudit(@RequestBody NewPurchaseVo newPurchaseVo){
        return new Result<>(200,"添加成功", purchaseItemService.erpAddPurchaseToAudit(newPurchaseVo));
    }


    @GetMapping("/getPurchaseItemById/{purchaseId}")
    @ApiOperation("根据采购单据ID查询==>采购详情信息")
    public Result<List<PurchaseItem>> getPurchaseItemById(@PathVariable String purchaseId){

        return new Result<>(200,"查询成功",purchaseItemService.getPurchaseItemById(purchaseId));
    }

    @GetMapping("/queryPurchaseAndItemByPurchaseId/{purchaseId}")
    @ApiOperation("根据采购单ID查询采购单信息和详情【editPurchase】")
    public Result<Map<String, Object>> queryPurchaseAndItemByPurchaseId(@PathVariable String purchaseId){
        return new Result<>(200,"查询成功",purchaseItemService.queryPurchaseAndItemByPurchaseId(purchaseId));
    }
    @PostMapping("/listPurchasePendingForPage")
    @ApiOperation("分页查询所有的待审核采购单数据==>待审核数据【入库审核页面】")
    public Result<Page<Purchase>> listPurchasePendingForPage(@RequestBody PurchaseVo purchaseVo){
        return new Result<>(200,"查询成功",purchaseService.listPurchasePendingForPage(purchaseVo));

    }
    @PostMapping("/auditPass/{purchaseId}")
    @ApiOperation("根据id修改状态改为==>审核通过【入库审核页面】")
    public Result<Integer> auditPass(@PathVariable String purchaseId){
        return new Result<>(200,"审核通过", purchaseService.auditPass(purchaseId));
    }
    @PostMapping("/auditNoPass/{purchaseId}/{auditMsg}")
    @ApiOperation("根据id修改状态改==>审核不通过【入库审核页面】")
    public Result<Integer> auditNoPass(@PathVariable String purchaseId, @PathVariable String auditMsg){
        return new Result<>(200,"审核不通过", purchaseService.auditNoPass(purchaseId,auditMsg));
    }


}